﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Data;
using System.Data.Odbc;
using System.Runtime.Remoting.Messaging;

namespace addqualificationcodefile
{
    class addqualification
    {
        OdbcConnection donconnection = new OdbcConnection();
        OdbcDataAdapter donadapter = new OdbcDataAdapter();
        DataTable dondatatable = new DataTable();
        string pth = Environment.CurrentDirectory;
        public void dbConnect()
        {
            donconnection.ConnectionString = "Driver={Microsoft Access Driver (*.mdb, *.accdb)}" +
                ";DBQ=" + pth + "\\Database\\BenguetCorpEmployeeDatabase.accdb" +
                ";UID=" +
                ";PWD=";
            donconnection.Open();
        }
        public void dbQuery(string donSql)
        {
            donadapter.SelectCommand = new OdbcCommand(donSql, donconnection);
            dondatatable.Reset();
            dondatatable.Clear();
            donadapter.Fill(dondatatable);
            donconnection.Close();
        }
        public void donCommit()
        {
            OdbcCommandBuilder donconnectionb = new OdbcCommandBuilder(donadapter);

            donadapter.Update(dondatatable);

        }
        public DataTable donResult
        {
            get { return dondatatable; }
        }



        //adding qualification asynchronously
        public void donAdd(string employeenumber, string qualification)
        {
            DataRow dondr = dondatatable.NewRow();
            dondr["fEmployeeNumber"] = employeenumber;
            dondr["fQualifiedFields"] = qualification;
            dondatatable.Rows.Add(dondr);
        }
        delegate void addprofile(string employeenumber, string qualification);
        public void asyncaddqualification(string employeenumber, string qualification)
        {
            addprofile ap = new addprofile(donAdd);
            AsyncCallback ac = new AsyncCallback(cbaddprofile);
            IAsyncResult ar = ap.BeginInvoke(employeenumber, qualification, ac, null);
        }
        void cbaddprofile(IAsyncResult ar)
        {
            addprofile ap = (addprofile)((AsyncResult)ar).AsyncDelegate;
            ap.EndInvoke(ar);
            onaddcompleted(null, null);
        }
        public event EventHandler addcompleted;
        protected virtual void onaddcompleted(object sender, EventArgs e)
        {
            if (addcompleted != null) addcompleted(sender, e);
        }
        //end of adding asynchronously
    }
}